<?php

  $WorkTable = &$_SQL_TABLE[$GlobPart];

  $TabFields['b'] = getFieldNamesWithLangs($WorkTable, array('title'));
  $TabFields['bg'] = getFieldNamesWithLangs($_SQL_TABLE['block_group'], array('title'));
  $TabFields['nt'] = getFieldNamesWithLangs($_SQL_TABLE['news_type'], array('title'));

  $BlockGroupsSelect = array_kv(getTableAsArray($_SQL_TABLE['block_group'], $TabFields['bg']['title'], array(), '', 'id,'.$TabFields['bg']['title']), $TabFields['bg']['title'], 'id');
  $NewsTypesSelect = array_kv(getTableAsArray($_SQL_TABLE['news_type'], $TabFields['nt']['title'], array(), '', 'id,'.$TabFields['nt']['title']), $TabFields['nt']['title'], 'id');

  if($_REQUEST['mode'] == $GlobPart)
  {
    $PageTitle = '$language["admin"]["blocks"]." :: ".$Item["'.$TabFields['b']['title'].'"];';
  }
  else
  {
  	$PageTitle = '$language["admin"]["blocks"];';
  	$AloneMode = $GlobPart;

  	$Query['FromTables'] = 	$WorkTable." b
  							LEFT JOIN ".$_SQL_TABLE['block_group']." bg ON bg.id = b.block_group
  							LEFT JOIN ".$_SQL_TABLE['news_type']." nt ON nt.id = b.news_type
  							";
  	$Query['Fields'] = "b.*, bg.".$TabFields['bg']['title']." AS block_group, IF(b.news_type > 0, nt.".$TabFields['nt']['title'].", ' ') AS news_type";
  	$Query['TabOrder'] = "b.";
  	$Query['Where'] = "";
  	$Query['GroupBy'] = "";

  	$EnableFilter = true;

  	$listInfo['where']['block_group'] = array(
  								'simple' => 'y',
  								'SQLField' => "b.block_group = '".$CONFIG['AdminFilterValuePat']."'",
  								'type' => 'select',
  								'title' => $language['admin']['blockGroup'],
  								'values' => array('' => $language['admin']['all']) + $BlockGroupsSelect,
  								'JSact' => '',
  								);

  	$listInfo['where']['news_type'] = array(
  								'simple' => 'y',
  								'SQLField' => "b.news_type = '".$CONFIG['AdminFilterValuePat']."'",
  								'type' => 'select',
  								'title' => $language['admin']['newsType'],
  								'values' => array('' => $language['admin']['all']) + $NewsTypesSelect,
  								'JSact' => '',
  								);

    require_once __CFG_PATH_CODE_ADMIN."admin.filter.inc";
  }

  $ConfLangArr = array(
				'title_' => array(
								'type' => 'input',
								'title' => $language['admin']['name'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST,
								'useInList' => $CONFIG['useInListSort'],
								'required' => $CONFIG['AdminReqPatAll'],
								'makeSameValue' => 'linkname',
								'makeSameValueFrom' => 'title_'.$CONFIG['SiteLanguage'],
								'makeSameValueFunc' => 'makeLinkName(this.value.toLowerCase())',
								'maxlength' => '100',
								'size' => '40',
								),
				'title_all_' => array(
								'type' => 'input',
								'title' => $language['admin']['linkAllTitle'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST,
								'maxlength' => '100',
								'size' => '40',
								)
  );

  $GeneratedLangArr = getAdminConfigArrayWithLangs($ConfLangArr, $SITE_LANGS);

  $LinkName = make_linkname($_POST['linkname']);
  $_SQL_TABLE_FIELDS[$GlobPart] = $GeneratedLangArr + array(

				'linkname' => array(
								'type' => 'input',
								'title' => $language['admin']['linkName'],
								'addVariable' => $LinkName,
								'useInAddForm' => 'y',
								'unique' => 'y',
								'useInList' => $CONFIG['useInListSort'],
								'useInListEdit' => 'y',
								'required' => $CONFIG['AdminReqPatLinkName'],
								'textUnderField' => '<span class="red">'.$language['admin']['latinAlphAttention'].'</span>',
								'maxlength' => '50',
								'size' => '60',
								),

				'code' => array(
								'type' => 'input',
								'title' => $language['admin']['code'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['code'],
								'useInList' => $CONFIG['useInListSort'],
								'required' => $CONFIG['AdminReqPatSymbols'],
								'editFormOther' => 'disabled',
								'maxlength' => '50',
								'size' => '40',
								'unique' => 'y',
								),

				'block_group' => array(
								'type' => 'select',
								'title' => $language['admin']['blockGroup'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['block_group'],
								'useInList' => $CONFIG['useInListSort'],
								'values' => $BlockGroupsSelect,
								'orderby' => $TabFields['bg']['title'].',b.'.$TabFields['b']['title'],
								'tabord' => 'bg.',
								'required' => $CONFIG['AdminReqPatAll'],
								),

				'news_type' => array(
								'type' => 'select',
								'title' => $language['admin']['newsType'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['news_type'],
								'useInList' => $CONFIG['useInListSort'],
								'values' => array('0' => $language['admin']['none']) + $NewsTypesSelect,
								'orderby' => $TabFields['nt']['title'].',b.'.$TabFields['b']['title'],
								'tabord' => 'nt.',
								'required' => $CONFIG['AdminReqPatAll'],
								),

				'position' => array(
								'type' => 'input',
								'title' => $language['admin']['position'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['position'],
								'useInList' => $CONFIG['useInListSort'],
								'allowEmpty' => 'y',
								'inListEdit' => 'list_input',
								'useInListEdit' => 'y',
								'size' => '3',
								'maxlength' => '3',
								),

				'news_count' => array(
								'type' => 'input',
								'title' => $language['admin']['newsCount'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['news_count'],
								'useInList' => $CONFIG['useInListSort'],
								'allowEmpty' => 'y',
								'inListEdit' => 'list_input',
								'useInListEdit' => 'y',
								'size' => '2',
								'maxlength' => '2',
								),

				'active' => array(
								'type' => 'select_link',
								'title' => $language['admin']['status'],
								'formid' => $CONFIG['activeFormName'],
								'addVariable' => 'y',
								'noUseInEdit' => 'y',
								'useInList' => $CONFIG['useInListSort'],
								'inListEdit' => 'select_link',
								'values' => array(
											'y' => array(
													'title' => $language['admin']['active'],
													'className' => 'active',
													'formFields' => array(
																	'act' => 'status',
																	'varvalue' => 'n',
																	'varname' => 'active',
																	getKeyVarName() => '{$Item.$WorkTableKeyFieldName}',
													),
											),
											'n' => array(
													'title' => $language['admin']['inactive'],
													'className' => 'inactive',
													'formFields' => array(
																	'act' => 'status',
																	'varvalue' => 'y',
																	'varname' => 'active',
																	getKeyVarName() => '{$Item.$WorkTableKeyFieldName}',
													),
											),
								),
				),

				'date' => array(
								'type' => 'value',
								'title' => $language['admin']['date'],
								'addVariable' => 'NOW()',
								'addVarType' => $CONFIG['VarTypeSQLFunction'],
								'useInList' => $CONFIG['useInListSort'],
								'useInListEdit' => 'y',
								),

  );

  $_SQL_TABLE_EDIT_FORMS[$GlobPart] = array('active');

  //$NoUse['DeleteButton'] = 'y';
  /*$NoUse['ActivateButton'] = 'y';
  $NoUse['DeactivateButton'] = 'y';*/

?>